package com.xuantu.learn.guava;

import java.util.Set;

import com.google.common.base.Optional;

public class OptionalTest {

	public static void main(String[] args) {
		Optional<Long> value = Optional.fromNullable(null);
		
		//System.out.println("value = " + value.get());// value=null时调用get()时报异常,应调用orNull();
		if(value.isPresent()==true){
            System.out.println("获得返回值: " + value.get());     
        }else{
                
            System.out.println("获得返回值: " + value.or(-12L));    
        }
		
		System.out.println("获得返回值 orNull: " + value.orNull());
		
		Optional<Long> valueNoNull = Optional.of(12L);
		System.out.println("valueNoNull = " + valueNoNull.get());
        if(valueNoNull.isPresent()==true){
            Set<Long> set=valueNoNull.asSet();
            System.out.println("获得返回值 set 的 size : " + set.size());    
            System.out.println("获得返回值: " + valueNoNull.get());     
        }else{
            System.out.println("获得返回值: " + valueNoNull.or(-12L));    
        }
        
        System.out.println("获得返回值 orNull: " + valueNoNull.orNull());
	}

}
